/*
 * @Title: 微信群分享
 * @Author: zhj
 * @Date:   2019-1-9
 * @Last Modified by:   zhj
 * @Last Modified time: 2019-1-9
 */
var dataInfo = {},
	template = {
		init: function() {
			Vue.use(VueLazyload, {
				preLoad: 1.3,
				error: 'https://h5.meetao.com/img/product/init.png',
				loading: 'https://h5.meetao.com/img/product/init.png',
				attempt: 1
			});
			dataInfo.init = new Vue({
				el: '#app',
				data: {
					all: false, //loadOver - show
					popupShow: false, //底部弹框开关
					loading: false,
					isLoading: false,
					finished: false,
					pullShow: true,
					pageNo: 1, //页数
					searchPage: 1, //搜索数据页数
					pageSize: 20, //每页显示数据总数
					PtListData: [], //拼团列表
					noData: false, //无数据显示
					columns: [], //分享群数据
					searchInput: "", //搜索内容
					bottowPopup: {
						shareShow: false
					},
					maskShow: false, //蒙版显示
					addClass: false, //添加class
				},
				methods: {
					init: function() {
						dataInfo.init.getWXGroupList();
					},
					popupClick: function() { //分享事件
						dataInfo.init.popupShow = true;
					},
					onConfirm: function(value, index) { //确定
						dataInfo.init.popupShow = false;
						dataInfo.init.bottowPopup.shareShow = true;
						dataInfo.init.maskShow = true;
					},
					onCancel: function() { //取消
						dataInfo.init.popupShow = false;
					},
					hideMask: function() { //取消蒙版
						dataInfo.init.bottowPopup.shareShow = false;
						dataInfo.init.maskShow = false;
						dataInfo.init.addClass = false;
					},
					searchClick: function() { //搜索框点击事件
						dataInfo.init.addClass = true;
						dataInfo.init.maskShow = true;
					},
					closeSearch: function() { //关闭搜索框
						dataInfo.init.addClass = false;
						dataInfo.init.maskShow = false;
					},
					cloceInput: function() { //清除输入内容
						dataInfo.init.searchInput = "";
					},
					searchGoods: function(event) { //点击键盘搜索事件
						if(event.keyCode == 13) { //如果按的是enter键 13是enter 
							event.preventDefault(); //禁止默认事件（默认是换行）
							dataInfo.init.addClass = false;
							dataInfo.init.maskShow = false;
							dataInfo.init.all = false;
							ajaxTemplate(addressTest + SERVICE.searchResources, function(data) {
								var daTa = data.data.result;
								dataInfo.init.PtListData = [];
								if(data.tag == 0) {
									dataInfo.init.PtListData = JSON.parse(JSON.stringify(dataInfo.init.PtListData.concat(daTa)));
									console.log(dataInfo.init.PtListData);
									if(daTa.length < dataInfo.init.pageSize) {
										dataInfo.init.finished = true;
										dataInfo.init.PtListData.length == 0 ? dataInfo.init.noData = true : dataInfo.init.all = true;
									} else {
										dataInfo.init.finished = false;
									};
									dataInfo.init.loading = false;
									dataInfo.init.isLoading = false;
								} else {

								}
							}, {
								type: "fxgoods",
								content: dataInfo.init.searchInput,
								limit: dataInfo.init.pageSize,
								page: dataInfo.init.searchPage++
							})
						}
					},
					onLoad: function() { //列表上拉加载
						this.getgrouplist();
					},
					onRefresh: function() { //列表下拉刷新
						this.PtListData = [];
						this.pageNo = 1;
						dataInfo.init.all = false;
						setTimeout(function() {
							if(dataInfo.init.PtListData.length == 0) {
								dataInfo.init.getgrouplist();
							}
						}, 500);
					},
					getWXGroupList: function() { //获取微信群
						ajaxTemplate(addressUrl + SERVICE.WXList, function(data) {
							if(data.tag == 0) {
								for(let i in data.data.result) {
									dataInfo.init.columns[i] = data.data.result[i].chatroom_showname;
								}
								console.log(dataInfo.init.columns);
							} else {

							}
						}, {

						})
					},
					getgrouplist: function() { //获取微信分享商品信息
						ajaxTemplate(addressUrl + SERVICE.queryFxGoodsListV2, function(data) {
							var daTa = data.data.result;
							if(data.tag == 0) {
								dataInfo.init.PtListData = JSON.parse(JSON.stringify(dataInfo.init.PtListData.concat(daTa)));
								if(daTa.length < dataInfo.init.pageSize) {
									dataInfo.init.finished = true;
									dataInfo.init.PtListData.length == 0 ? dataInfo.init.noData = true : dataInfo.init.all = true;
								} else {
									dataInfo.init.finished = false;
								};
								dataInfo.init.loading = false;
								dataInfo.init.isLoading = false;
							} else {

							}
						}, {
							limit: dataInfo.init.pageSize,
							page: dataInfo.init.pageNo++
						})
					},
				}
			});
			dataInfo.init.init();
		}
	};
template.init();